home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Pyramid / Source / Kitchen.m < prev    next >
Text File  |  1993-09-15  |  6KB  |  301 lines

  1. /*    Kitchen.m - Model for simple kitchen
  2.  *    Copyright (C) 1993 Corona Design, Inc. All rights reserved.
  3.  *
  4.  *    Abstract
  5.  *        This model shows a simple kitchen with a counter
  6.  *        and a bookcase on the wall.
  7.  *
  8.  *    RCS path: 
  9.  *        $Source: /Users/pkron/Projects/voxel/Pyramid/RCS/Kitchen.m,v $
  10.  *    Modified: $Date: 93/09/15 12:35:00 $ by $Author: pkron $
  11.  *    Current State: $State: Exp $ locked by $Locker:  $
  12.  */
  13.  
  14. #import     "Kitchen.h"
  15.  
  16. #import        "SpatialView.h"
  17.  
  18.  
  19. static void
  20. pointCopy( POINT *a, POINT *b)
  21.     {
  22.     (*a)[0] = (*b)[0];
  23.     (*a)[1] = (*b)[1];
  24.     (*a)[2] = (*b)[2];
  25.     (*a)[3] = (*b)[3];
  26.     }
  27.  
  28.  
  29. @implementation Kitchen
  30.  
  31.  
  32.                                 // utility routine to draw a line
  33.                                 // to a point in space
  34. - drawLineTo: (POINT *)aPoint
  35.     {
  36.                                 // map and project the point first
  37.     map( transform, aPoint);
  38.     project( aPoint);
  39.     PSlineto( (*aPoint)[0], (*aPoint)[1]);
  40.  
  41.     return( self);
  42.     }
  43.     
  44.  
  45. #define    LIGHT_BROWN        127./255, 63./255, 19./255
  46. #define    MEDIUM_BROWN    102./255, 51./255, 15./255 
  47. #define    BROWN            77./255, 39./255, 12./255    
  48. #define    DARK_BROWN        46./255, 23./255, 7./255
  49.  
  50. #define    GRAY            102./255, 102./255, 102./255    
  51. #define    LIGHT_GRAY        153./255, 153./255, 153./255    
  52. #define    DARK_GRAY        50./255, 50./255, 50./255    
  53.     
  54. - drawModel: (MATRIX)aTransform : (NXRect *)clip;
  55.     {
  56.     POINT        distance;
  57.     
  58.     counterWidth = 1.0, counterDepth = .4;
  59.     counterHeight = .3;
  60.     shelfOriginY = .1, shelfOriginZ = .4, shelfHeight = .2;
  61.     shelfWidth = .1, shelfDepth = .9;
  62.     
  63.     transform = aTransform;
  64.     
  65.                                 // X infinity
  66.     distance[0] = -1000;
  67.     distance[1] = 0;
  68.     distance[2] = 0;
  69.     distance[3] = 1;
  70.     map( transform, &distance);
  71.     project( &distance);
  72.     
  73.                                 // draw horizon
  74.     PSmoveto( -10, distance[1] + .5);
  75.     PSrlineto( 20, 0);
  76.     PSsetlinewidth( 1);
  77.     PSsetrgbcolor( 0, 1, 1);
  78.     PSstroke();
  79.     
  80.     PSsetrgbcolor( GRAY);        // DK Brown    
  81.     [self drawPlane: 0 : 0 : 0 
  82.                     width: counterWidth : 0 : counterHeight];
  83.     PSsetrgbcolor( DARK_GRAY);
  84.     [self drawPlane: counterWidth : 0 : 0 
  85.                     width: 0 : counterDepth : counterHeight];
  86.     PSsetrgbcolor( LIGHT_GRAY);
  87.     [self drawPlane: 0 : 0 : counterHeight 
  88.                     width: counterWidth : counterDepth : 0];
  89.  
  90.     PSsetrgbcolor( MEDIUM_BROWN);
  91.     [self drawPlane: 0 : shelfOriginY + shelfDepth : shelfOriginZ 
  92.                     width: shelfWidth : 0 : shelfHeight];
  93.  
  94.     PSsetrgbcolor( DARK_BROWN);
  95.     [self drawPlane: 0 : shelfOriginY : shelfOriginZ 
  96.                     width: shelfWidth : shelfDepth : 0];
  97.  
  98.     PSsetrgbcolor( DARK_BROWN);
  99.     [self drawPlane: 0 : shelfOriginY : shelfOriginZ 
  100.                     width: 0 : shelfDepth : shelfHeight];
  101.  
  102.     PSsetrgbcolor( LIGHT_BROWN);
  103.     [self drawPlane: 0 : shelfOriginY : shelfOriginZ + shelfHeight
  104.                     width: shelfWidth : shelfDepth : 0];
  105.  
  106.     PSsetrgbcolor( MEDIUM_BROWN);
  107.     [self drawPlane: 0 : shelfOriginY : shelfOriginZ 
  108.                     width: shelfWidth : 0 : shelfHeight];
  109.  
  110.     return( self);
  111.     }
  112.  
  113.                                 // draw lines from key points
  114.                                 // to infinite axis points
  115. - drawVanishingPoints: (MATRIX)aTransform : (NXRect *)clip;
  116.     {
  117.     POINT    distance;
  118.     POINT    aPoint;
  119.         
  120.                                 // X infinity
  121.     distance[0] = -1000;
  122.     distance[1] = 0;
  123.     distance[2] = 0;
  124.     distance[3] = 1;
  125.     map( transform, &distance);
  126.     project( &distance);
  127.     
  128.     aPoint[0] = 0;
  129.     aPoint[1] = 0;
  130.     aPoint[2] = 0;
  131.     aPoint[3] = 1;
  132.     PSmoveto( distance[0], distance[1]);
  133.     [self drawLineTo: &aPoint];
  134.     
  135.     aPoint[0] = 0;
  136.     aPoint[1] = counterDepth;
  137.     aPoint[2] = counterHeight;
  138.     aPoint[3] = 1;
  139.     PSmoveto( distance[0], distance[1]);
  140.     [self drawLineTo: &aPoint];
  141.     
  142.     aPoint[0] = 0;
  143.     aPoint[1] = 0;
  144.     aPoint[2] = counterHeight;
  145.     aPoint[3] = 1;
  146.     PSmoveto( distance[0], distance[1]);
  147.     [self drawLineTo: &aPoint];
  148.     
  149.     aPoint[0] = 0;
  150.     aPoint[1] = shelfOriginY;
  151.     aPoint[2] = shelfOriginZ;
  152.     aPoint[3] = 1;
  153.     PSmoveto( distance[0], distance[1]);
  154.     [self drawLineTo: &aPoint];
  155.     
  156.     aPoint[0] = 0;
  157.     aPoint[1] = shelfOriginY;
  158.     aPoint[2] = shelfOriginZ + shelfHeight;
  159.     aPoint[3] = 1;
  160.     PSmoveto( distance[0], distance[1]);
  161.     [self drawLineTo: &aPoint];
  162.     
  163.     PSsetrgbcolor( 1, 0, 0);
  164.     PSsetlinewidth(0);
  165.     PSstroke();
  166.  
  167.                                 // Y infinity
  168.     distance[0] = 0;
  169.     distance[1] = 1000;
  170.     distance[2] = 0;
  171.     distance[3] = 1;
  172.     map( transform, &distance);
  173.     project( &distance);
  174.     
  175.     aPoint[0] = counterWidth;
  176.     aPoint[1] = counterDepth;
  177.     aPoint[2] = 0;
  178.     aPoint[3] = 1;
  179.     PSmoveto( distance[0], distance[1]);
  180.     [self drawLineTo: &aPoint];
  181.     
  182.     aPoint[0] = counterWidth;
  183.     aPoint[1] = counterDepth;
  184.     aPoint[2] = counterHeight;
  185.     aPoint[3] = 1;
  186.     PSmoveto( distance[0], distance[1]);
  187.     [self drawLineTo: &aPoint];
  188.     
  189.     aPoint[0] = 0;
  190.     aPoint[1] = shelfOriginY + shelfDepth;
  191.     aPoint[2] = shelfOriginZ;
  192.     aPoint[3] = 1;
  193.     PSmoveto( distance[0], distance[1]);
  194.     [self drawLineTo: &aPoint];
  195.     
  196.     aPoint[0] = 0;
  197.     aPoint[1] = shelfOriginY + shelfDepth;
  198.     aPoint[2] = shelfOriginZ + shelfHeight;
  199.     aPoint[3] = 1;
  200.     PSmoveto( distance[0], distance[1]);
  201.     [self drawLineTo: &aPoint];
  202.     
  203.     aPoint[0] = shelfWidth;
  204.     aPoint[1] = shelfOriginY + shelfDepth;
  205.     aPoint[2] = shelfOriginZ;
  206.     aPoint[3] = 1;
  207.     PSmoveto( distance[0], distance[1]);
  208.     [self drawLineTo: &aPoint];
  209.     
  210.     PSsetrgbcolor( 1, 0, 0);
  211.     PSsetlinewidth(0);
  212.     PSstroke();
  213.  
  214.     return( self);
  215.     }
  216.     
  217.  
  218.                                 // draw a spatial plane, given
  219.                                 // its origin in 3-space and
  220.                                 // the widths of its dimensions
  221.                                 // (One width must be 0)    
  222. - drawPlane: (float)x : (float)y : (float)z 
  223.             width: (float)wx :(float)wy : (float)wz
  224.     {
  225.     POINT    space;
  226.     POINT    mapped;
  227.  
  228.     space[0] = x;
  229.     space[1] = y;
  230.     space[2] = z;
  231.     space[3] = 1;
  232.  
  233.     pointCopy( &mapped, &space);
  234.     map( transform, &mapped);
  235.     project( &mapped);
  236.     PSmoveto( mapped[0], mapped[1]);
  237.  
  238.     pointCopy( &mapped, &space);
  239.     if ( wx EQ 0.0 )
  240.         {
  241.         mapped[1] += wy;
  242.         [self drawLineTo: &mapped];
  243.  
  244.         pointCopy( &mapped, &space);
  245.         mapped[1] += wy;
  246.         mapped[2] += wz;
  247.         [self drawLineTo: &mapped];
  248.  
  249.         pointCopy( &mapped, &space);
  250.         mapped[2] += wz;
  251.         [self drawLineTo: &mapped];
  252.         }
  253.     
  254.     else if ( wy EQ 0.0 )
  255.         {
  256.         mapped[0] += wx;
  257.         [self drawLineTo: &mapped];
  258.  
  259.         pointCopy( &mapped, &space);
  260.         mapped[0] += wx;
  261.         mapped[2] += wz;
  262.         [self drawLineTo: &mapped];
  263.  
  264.         pointCopy( &mapped, &space);
  265.         mapped[2] += wz;
  266.         [self drawLineTo: &mapped];
  267.         }
  268.     
  269.     else
  270.         {
  271.         mapped[0] += wx;
  272.         [self drawLineTo: &mapped];
  273.  
  274.         pointCopy( &mapped, &space);
  275.         mapped[0] += wx;
  276.         mapped[1] += wy;
  277.         [self drawLineTo: &mapped];
  278.  
  279.         pointCopy( &mapped, &space);
  280.         mapped[1] += wy;
  281.         [self drawLineTo: &mapped];
  282.         }
  283.         
  284.     PSclosepath();
  285.     PSfill();
  286.     
  287.     return( self);
  288.     }
  289.  
  290.  
  291. @end
  292.  
  293. #ifdef    _LOG
  294. /*
  295.  *    $Log:    Kitchen.m,v $
  296. Revision 1.1  93/09/15  12:35:00  pkron
  297. Created.
  298.  
  299.  */
  300. #endif        
  301.